package com.shijunhao.graduation.listener;

import com.shijunhao.graduation.event.LoginLogEvent;
import com.shijunhao.graduation.service.business.ISystemLoginLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author: shijunhao
 * @date: 2022/3/16 16:11
 * @description:
 */
@Component
public class LoginEventListener {

    private final ISystemLoginLogService loginLogService;

    @Autowired
    public LoginEventListener(ISystemLoginLogService loginLogService) {
        this.loginLogService = loginLogService;
    }

    @Async
    @Order
    @EventListener
    public void onApplicationEvent(LoginLogEvent event) {
        loginLogService.insertOne(event.getSource());
    }

}
